package ex4;

/**
 * @author: knowno
 * @create: 2024-09-06 14:00
 * @Version 1.0
 **/
public class TestObject {
    public static void main(String[] args) {

        Object o1 = new Object();
        Object o2 = new Object();
        //常见方法 =>Object中的equals是比较的地址
        boolean equals = o1.equals(o2);
        System.out.println(equals);

        System.out.println("*********String=>Object,重写了equals方法,实现了值比较****************");
        String str1 = new String("abc");
        String str2 = new String("abc");
        System.out.println(str1.equals(str2));

        //toString
        Human a = new Human(1, "a");
        System.out.println(a.toString());


    }
}

class Human{
    private int id;
    private String name;

    @Override
    public String toString() {
        return "Human{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    public Human(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
